//
//  DYItemView.m
//  kafuMerchant
//
//  Created by 帝云科技 on 2018/9/11.
//  Copyright © 2018年 帝云科技. All rights reserved.
//

#import "DYItemView.h"

@interface DYItemView ()

@property (nonatomic,strong)UILabel *line1;
@property (nonatomic,strong)UILabel *line2;
@property (nonatomic,strong)UILabel *line3;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UIButton *managerButton1;
@property (nonatomic,strong)UIButton *managerButton2;
@property (nonatomic,strong)UIButton *managerButton3;


@end

@implementation DYItemView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
-(void)initUI
{
    self.backgroundColor=WhiteColor;
    
    self.titleLabel = ({
        UILabel *label=[Utils labelWithTitleFontSize:14 textColor:[UIColor xhq_aTitle] alignment:1];
        label;
    });
    
    self.line1 = ({
        UILabel *line=[UILabel xhq_lineLabel];
        line;
    });
    
    self.line2 = ({
        UILabel *line=[UILabel xhq_lineLabel];
        line;
    });
    
    self.line3 = ({
        UILabel *line=[UILabel xhq_lineLabel];
        line;
    });
    
    self.managerButton1 = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(buttonClick:) target:self title:nil image:nil font:13 textColor:[UIColor xhq_aTitle]];
        button;
    });
    
    self.managerButton2 = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(buttonClick:) target:self title:nil image:nil font:13 textColor:[UIColor xhq_aTitle]];
        button;
    });
    
    self.managerButton3 = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(buttonClick:) target:self title:nil image:nil font:13 textColor:[UIColor xhq_aTitle]];
        button;
    });
    
    [self addSubview:self.titleLabel];
    [self addSubview:self.managerButton1];
    [self addSubview:self.managerButton2];
    [self addSubview:self.managerButton3];
    
    [self addSubview:self.line1];
    [self addSubview:self.line2];
    [self addSubview:self.line3];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(BILIHEIGHT(10));
        make.centerX.equalTo(self);
    }];
    
    [self.line1 makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(0);
        make.top.equalTo(BILIHEIGHT(40));
        make.height.equalTo(BILIWIDTH(0.7));
    }];
    
    [self.managerButton1 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0);
        make.top.equalTo(self.line1.bottom);
        make.size.equalTo(CGSizeMake(kScreenWidth/3, BILIHEIGHT(90)));
    }];

    [self.managerButton2 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.managerButton1.right);
        make.top.width.height.equalTo(self.managerButton1);
    }];

    [self.managerButton3 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.managerButton2.right);
        make.top.width.height.equalTo(self.managerButton1);
    }];

    [self.line2 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.managerButton1.right);
        make.top.bottom.equalTo(self.managerButton1);
        make.width.equalTo(BILIWIDTH(0.7));
    }];

    [self.line3 makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.managerButton2.right);
        make.top.bottom.equalTo(self.managerButton1);
        make.width.equalTo(BILIWIDTH(0.7));
    }];
    
}
-(void)buttonClick:(UIButton *)button
{
    if (button==self.managerButton1) {
        !self.itemBlock?:self.itemBlock(1);
    }else if (button==self.managerButton2){
         !self.itemBlock?:self.itemBlock(2);
    }else{
        !self.itemBlock?:self.itemBlock(3);
    }
}
-(void)setTitle:(NSString *)title
{
    _title=title;
    self.titleLabel.text=title;
}
-(void)setDataArray:(NSArray *)dataArray
{
    _dataArray=dataArray;
    
    [self.managerButton1 setTitle:dataArray[0][@"title"] forState:UIControlStateNormal];
    [self.managerButton1 setImage:[UIImage imageNamed:dataArray[0][@"image"]] forState:UIControlStateNormal];
    [self.managerButton2 setTitle:dataArray[1][@"title"] forState:UIControlStateNormal];
    [self.managerButton2 setImage:[UIImage imageNamed:dataArray[1][@"image"]] forState:UIControlStateNormal];
    [self.managerButton3 setTitle:dataArray[2][@"title"] forState:UIControlStateNormal];
    [self.managerButton3 setImage:[UIImage imageNamed:dataArray[2][@"image"]] forState:UIControlStateNormal];


    [self.managerButton1 placeImageTitlePosition:ZYButtonImagePositionTop space:BILIHEIGHT(12)];
    [self.managerButton2 placeImageTitlePosition:ZYButtonImagePositionTop space:BILIHEIGHT(12)];
    [self.managerButton3 placeImageTitlePosition:ZYButtonImagePositionTop space:BILIHEIGHT(12)];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
